SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW [dbo].[DeliveryNoteHistory]
AS
SELECT  Prescription.PrescriptionID ,
        PrescriptionDetail.DrugId ,
        DrugDispo.DrugName ,
        SUM(Quantity) AS Quantity,
        Prescription.DeliveryDate ,
        Prescription.PatientCode ,
        Prescription.PatientName
FROM    PrescriptionDetail
        INNER JOIN Prescription ON PrescriptionDetail.PrescriptionID = Prescription.PrescriptionID
        INNER JOIN DrugDispo ON PrescriptionDetail.DrugId = DrugDispo.DrugId
WHERE   IsVoid = 0
GROUP BY PrescriptionDetail.DrugId ,
        Prescription.DeliveryDate ,
        Prescription.PatientName ,
        Prescription.PatientCode ,
        Prescription.PrescriptionID ,
        DrugDispo.DrugName
        
        
GO
